package animator.phantom.gui.flow;

/*
    Copyright Janne Liljeblad 2006,2007,2008

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import animator.phantom.gui.*;
import animator.phantom.controller.*;
import animator.phantom.project.*;
import animator.phantom.renderer.*;
import animator.phantom.renderer.param.*;
import animator.phantom.gui.timeline.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

public class RenderFlowViewButtons extends JPanel implements ActionListener
{
	private int UP_GAP = 0;
	private int DOWN_GAP = 0;

	private JButton toTimeline = new JButton( GUIResources.getIcon( GUIResources.toTimeline) ); 

	private JButton delete = new JButton( GUIResources.getIcon(GUIResources.deleteBoxes) );
	private JButton lineUpBoxes = new JButton( GUIResources.getIcon( GUIResources.lineUpBoxes) );
	private JButton connectBoxes = new JButton( GUIResources.getIcon(GUIResources.connectBoxes) );
	private JButton disConnectBoxes = new JButton( GUIResources.getIcon(GUIResources.disConnectBoxes) );

	private JButton setTarget = new JButton( GUIResources.getIcon( GUIResources.viewTarget ) );

	private JButton renameInFlow = new JButton( GUIResources.getIcon( GUIResources.renameInFlow ) );

	private JButton colorQButton = new JButton( GUIResources.getIcon(GUIResources.colorQButton) );
	private JButton gradientQButton = new JButton( GUIResources.getIcon( GUIResources.gradientQButton) );
	private JButton gaussianQButton = new JButton( GUIResources.getIcon(GUIResources.gaussianQButton) );
	private JButton mergeQButton = new JButton( GUIResources.getIcon( GUIResources.mergeQButton) );
	public JLabel infoText = new JLabel();

	public RenderFlowViewButtons( AnimatorFrame frame, TCPanel tcPanel, NormalizedTimelineDisplay normTline )
	{
		GUIResources.prepareMediumButton( delete, this, "Delete IOPs from flow" );
		GUIResources.prepareMediumButton( lineUpBoxes, this, "Line up selected boxes  F5" );
		GUIResources.prepareMediumButton( connectBoxes, this, "Connect selected boxes  F6" );
		GUIResources.prepareMediumButton( disConnectBoxes, this, "Disconnect selected boxes  F7" );
		GUIResources.prepareMediumButton( colorQButton, this, "Add Color IOP" );
		GUIResources.prepareMediumButton( gradientQButton, this, "Add Gradient IOP" );
		GUIResources.prepareMediumButton( gaussianQButton, this, "Add GaussianBlur IOP" );
		GUIResources.prepareMediumButton( mergeQButton, this, "Add Merge IOP" );
		GUIResources.prepareMediumButton( setTarget, this, "Set ViewEditor render target" );
		GUIResources.prepareMediumButton( renameInFlow, this, "rename selected Node" );

		GUIResources.prepareMediumWideButton( toTimeline, this, "To ClipEditor" );

		JPanel tcHolder = new JPanel();
		tcHolder.setLayout(new BoxLayout( tcHolder, BoxLayout.Y_AXIS));
		tcHolder.add( Box.createRigidArea( new Dimension( 0, 5 ) ) );
		tcHolder.add( tcPanel );

		JPanel normHolder = new JPanel();
		normHolder.setLayout(new BoxLayout( normHolder, BoxLayout.Y_AXIS));
		normHolder.add( Box.createRigidArea( new Dimension( 0, 9 ) ) );
		normHolder.add( normTline );
		normHolder.add( Box.createVerticalGlue() );

		setLayout(new BoxLayout( this, BoxLayout.X_AXIS));
		add( Box.createRigidArea( new Dimension( 15, 0 ) ) );
		//add( toTimeline );
		//add( Box.createRigidArea( new Dimension( 6, 0 ) ) );
		add( delete );
		add( lineUpBoxes );
		add( connectBoxes );
		add( disConnectBoxes );
		add( Box.createRigidArea( new Dimension( 6, 0 ) ) );
		add( setTarget );
		add( Box.createRigidArea( new Dimension( 6, 0 ) ) );
		add( renameInFlow );
		add( Box.createRigidArea( new Dimension( 6, 0 ) ) );
		add( tcHolder );
		add( normHolder );
		//add( Box.createRigidArea( new Dimension( 6, 0 ) ) );
		infoText.setFont( GUIResources.BASIC_FONT_12 );
		add( infoText );
		add( Box.createHorizontalGlue() );
	
		setBorder( BorderFactory.createEmptyBorder( UP_GAP, 0, DOWN_GAP, 0 ) );
	}

	public void setInfoText( String text )
	{
		infoText.setText( text );
		repaint();
	}
	
	public void actionPerformed(ActionEvent e)
	{
		//--- Delete selected boxes from flow view and nodes from flow.
		if( e.getSource() == delete )
			FlowController.deleteSelected();
		//--- Send selected iops to timeline
		if( e.getSource() == toTimeline )
			TimeLineController.sendClipsToTimeline();
		if( e.getSource() == lineUpBoxes )
			FlowController.arrangeBoxRow();
		if( e.getSource() == connectBoxes )
			FlowController.connectSelected();
		if( e.getSource() == disConnectBoxes )
			FlowController.disConnectSelected();
		if( e.getSource() == renameInFlow )
			MenuActions.renameSelected();
	
		if( e.getSource() == setTarget ) FlowController.viewTargetPressed();
	}
	
}//end class